package com.irdstudio.efp.console.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.console.service.dao.PrdInfoMapDao;
import com.irdstudio.efp.console.service.domain.PrdInfoMap;
import com.irdstudio.efp.console.service.facade.PrdInfoMapService;
import com.irdstudio.efp.console.service.vo.PrdInfoMapVO;
/**
 * <p>ServiceImpl: 信贷产品映射表				<p>
 * @author fuzm
 * @date 2018-05-23
 */
@Service("prdInfoMapService")
public class PrdInfoMapServiceImpl implements PrdInfoMapService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PrdInfoMapServiceImpl.class);

	@Autowired
	private PrdInfoMapDao prdInfoMapDao;
	
	/**
	 * 新增操作
	 */
	public int insertPrdInfoMap(PrdInfoMapVO inPrdInfoMapVo) {
		logger.debug("当前新增数据为:"+ inPrdInfoMapVo.toString());
		int num = 0;
		try {
			PrdInfoMap prdInfoMap = new PrdInfoMap();
			beanCopy(inPrdInfoMapVo, prdInfoMap);
			num = prdInfoMapDao.insertPrdInfoMap(prdInfoMap);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PrdInfoMapVO inPrdInfoMapVo) {
		logger.debug("当前删除数据条件为:"+ inPrdInfoMapVo);
		int num = 0;
		try {
			PrdInfoMap prdInfoMap = new PrdInfoMap();
			beanCopy(inPrdInfoMapVo, prdInfoMap);
			num = prdInfoMapDao.deleteByPk(prdInfoMap);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPrdInfoMapVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PrdInfoMapVO inPrdInfoMapVo) {
		logger.debug("当前修改数据为:"+ inPrdInfoMapVo.toString());
		int num = 0;
		try {
			PrdInfoMap prdInfoMap = new PrdInfoMap();
			beanCopy(inPrdInfoMapVo, prdInfoMap);
			num = prdInfoMapDao.updateByPk(prdInfoMap);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPrdInfoMapVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PrdInfoMapVO queryByPk(PrdInfoMapVO inPrdInfoMapVo) {
		
		logger.debug("当前查询参数信息为:"+ inPrdInfoMapVo);
		try {
			PrdInfoMap queryPrdInfoMap = new PrdInfoMap();
			beanCopy(inPrdInfoMapVo, queryPrdInfoMap);
			PrdInfoMap queryRslPrdInfoMap = prdInfoMapDao.queryByPk(queryPrdInfoMap);
			if (Objects.nonNull(queryRslPrdInfoMap)) {
				PrdInfoMapVO outPrdInfoMapVo = beanCopy(queryRslPrdInfoMap, new PrdInfoMapVO());
				logger.debug("当前查询结果为:"+ outPrdInfoMapVo.toString());
				return outPrdInfoMapVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PrdInfoMapVO> queryAllOwner(PrdInfoMapVO prdInfoMapVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PrdInfoMapVO> list = null;
		try {
			List<PrdInfoMap> prdInfoMaps = prdInfoMapDao.queryAllOwnerByPage(prdInfoMapVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ prdInfoMaps.size());
			pageSet(prdInfoMaps, prdInfoMapVo);
			list = (List<PrdInfoMapVO>) beansCopy(prdInfoMaps, PrdInfoMapVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PrdInfoMapVO> queryAllCurrOrg(PrdInfoMapVO prdInfoMapVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PrdInfoMap> prdInfoMaps = prdInfoMapDao.queryAllCurrOrgByPage(prdInfoMapVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+prdInfoMaps.size());
		List<PrdInfoMapVO> list = null;
		try {
			pageSet(prdInfoMaps, prdInfoMapVo);
			list = (List<PrdInfoMapVO>) beansCopy(prdInfoMaps, PrdInfoMapVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PrdInfoMapVO> queryAllCurrDownOrg(PrdInfoMapVO prdInfoMapVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PrdInfoMap> prdInfoMaps = prdInfoMapDao.queryAllCurrDownOrgByPage(prdInfoMapVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ prdInfoMaps.size());
		List<PrdInfoMapVO> list = null;
		try {
			pageSet(prdInfoMaps, prdInfoMapVo);
			list = (List<PrdInfoMapVO>) beansCopy(prdInfoMaps, PrdInfoMapVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	/**
	 * 根据条件查询信贷产品信息
	 * @param serno 流水号
	 * @param prdThlDri 产品类型
	 * @param agriFlg 是否农户
	 * @param repayWay 还款方式
	 * @param bizType 省信贷业务品种
	 * @param bizTypeName 业务品种名称
	 * @param bizTypeSub 业务品种细分
	 * @param bizTypeSubName 业务品种细分名称
	 */
	@SuppressWarnings("unchecked")
	public List<PrdInfoMapVO> queryPrdInfoMap(PrdInfoMapVO prdInfoMapVo) {
		List<PrdInfoMap> prdInfoMaps = prdInfoMapDao.queryPrdInfoMap(prdInfoMapVo);
		logger.debug("当前查询的结果集数量为:"+ prdInfoMaps.size());
		List<PrdInfoMapVO> list = null;
		try {
			list = (List<PrdInfoMapVO>) beansCopy(prdInfoMaps, PrdInfoMapVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}
}
